package com.example.yiqiuser.service.impl;

import com.example.yiqiuser.dao.IContactDao;
import com.example.yiqiuser.entity.Contact;
import com.example.yiqiuser.service.IContactService;
import com.example.yiqiuser.util.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ fileName:PtFcontactServiceImpl
 * @ description:
 * @ author:chen
 * @ createTime:2023/3/31 14:13
 * @ version:1.0.0
 */
@Service
public class IContactServiceImpl implements IContactService {
    @Resource
    private IContactDao contactDao;

    @Override
    public List<Contact> queryByUserId(String userId) {
        return contactDao.queryByUserId(userId);
    }

    @Override
    public PageInfo queryPage(Page<Contact> page) {
        PageHelper.startPage(page.getPageNo(), page.getPageSize());
        return new PageInfo(contactDao.queryByParam(page.getData()));
    }

    @Override
    public List<Contact> queryAll() {
        return contactDao.queryAll();
    }

    @Override
    public Contact queryById(int id) {
        List<Contact> contacts = contactDao.queryById(id);
        if (contacts!=null&&contacts.size()>0) {
            return contacts.get(0);
        }
        return null;
    }

    @Override
    public int addContact(Contact contact) {
        return contactDao.addContact(contact);
    }

    @Override
    public int updateContact(Contact contact) {
        return contactDao.updateContact(contact);
    }

    @Override
    public int deleteById(int id) {
        return contactDao.deleteById(id);
    }
}
